// pages/goods-specs/index.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        show: {
            type: Boolean,
            value: false
        },
        btnText: {
            type: String,
            value: ''
        },
        dataObj: {
            type: Object,
            value: {}
        },
        // 规格商品列
        option: {
            type: Array,
            value: []
        }
    },
   
    /**
     * 组件的初始数据
     */
    data: {
        isShow: false,
        active: 0,
        activeChild: 0,
        goodsList: [{
            goodsImg: "/images/element_christmas_xpzq@2x.png",
            goodsName: "商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称",
            goodsPrice: "310.00",
            goodsSpecs: "规格规格规格个规格规格规格规格规格规格个规格规格规格",
            goodsSpecsCount: 2
        }, ],
        specsList: ['2.5kg', '3.5kg'],
        active: 0, //当前选中规格
        specsName: "",
        count: 1,
        thumb: '',
        property_price:'',
        propertydata:{}
    },

    observers: {
        'dataObj': function (newVal, oldVal) {
            console.log('接收到的对象：', newVal);
        },
        'show': function (newVal, oldVal) {
            if (newVal && this.data.dataObj.tips == 1) {//一件代发
                this.data.propertydata = {productid: this.data.dataObj.productid}
            }
            this.setData({isShow:newVal})
           
        }
    },
    /**
     * 组件的方法列表
     */
    methods: {
        /**
         * 选择规格回调函数方法
         * @param {*} e 
         */
        handleSelSpecs(e) {
            const {
                index,
                value
            } = e.currentTarget.dataset
            this.setData({
                active: index,
                specsName: value
            })
        },
        handleSelSpecs(e) {
            const index = e.currentTarget.dataset.index;
            this.setData({
                active: index,
                activeChild: 0, // 重置第二个规格栏的选中状态
                thumb: this.data.dataObj.property[index].child[this.data.activeChild].img,
                property_price:this.data.dataObj.property[index].child[this.data.activeChild].price
            });

        },
        handleSelSpecsChild(e) {
            const index = e.currentTarget.dataset.index;
            this.setData({
                activeChild: index,
                property_price:this.data.dataObj.property[this.data.active].child[index].price
            });
            console.log('e',e)
            this.data.propertydata = {...e.currentTarget.dataset.value}
        },
        /**
         * 商品数量变化回调函数方法
         * @param {*} e 
         */
        handleNumChange(e) {
            this.setData({
                count: e.detail
            })
        },
        /**
         * 确认按钮回调函数方法
         */
        onConfirm() {
            let num 
           
            this.triggerEvent('confirm', {
               
            })
        },
        /**
         * 关闭
         */
        close() {
            this.triggerEvent('close')
        }
    }
})